#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e7+400;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
LL res[27],L[maxn];
LL dp[maxn][4];
int main(void){
    LL n,m;n=read();m=read();
    scanf("%s",str+1);
    LL sum=0;
    LL l=1;LL r=0;
    while(r<=n){
        ++r;
        ++res[str[r]-'a'+1];
        while(res[str[r]-'a'+1]>m){
            --res[str[l]-'a'+1];
            ++l;
        }
        L[r]=l;
    }
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=3;j++){
            dp[i][j]=max(dp[i-1][j],dp[L[i]-1][j-1]+i-L[i]+1);
        }
    }
    cout<<dp[n][3]<<"\n";
   	return 0;
}
